import React from 'react'

export default class extends React.Component {
  state = {
    count: 0
  }
  onIncrement = (res) => {
    this.setState({
      count: this.state.count + res
    })
  }
  render() {
    return (
      <div style={{ backgroundColor: 'pink' }}>
        <Child1 count={this.state.count}></Child1>
        <Child2 onIncrement={this.onIncrement}></Child2>
      </div>
    )
  }
}

class Child1 extends React.Component {
  render() {
    return <h1>计数器：{this.props.count}</h1>
  }
}
class Child2 extends React.Component {
  handleClick = () => {
    this.props.onIncrement(2)
  }
  render() {
    return <button onClick={this.handleClick}>修改数据</button>
  }
}
